package com.mofang.ticketing.user.serve.merchant.controller;


import com.mofang.ticketing.common.core.dto.PrimaryIdDTO;
import com.mofang.ticketing.common.core.page.PageResult;
import com.mofang.ticketing.common.core.result.Result;
import com.mofang.ticketing.common.core.urls.user.merchant.MerchantUrl;
import com.mofang.ticketing.common.log.SystemLog;
import com.mofang.ticketing.user.serve.merchant.dto.request.MerchantAddReqDTO;
import com.mofang.ticketing.user.serve.merchant.dto.request.MerchantListPageReqDTO;
import com.mofang.ticketing.user.serve.merchant.dto.request.MerchantUpdateReqDTO;
import com.mofang.ticketing.user.serve.merchant.dto.response.MerchantDetailRespDTO;
import com.mofang.ticketing.user.serve.merchant.dto.response.MerchantListPageRespDTO;
import com.mofang.ticketing.user.serve.merchant.dto.response.MerchantSelectRespDTO;
import com.mofang.ticketing.user.serve.merchant.service.MerchantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author LGC
 */
@Api(tags = "商户管理")
@RestController
public class MerchantController {

    @Resource
    private MerchantService merchantService;

    @ApiOperation(value = "商户详情")
    @PostMapping(value = MerchantUrl.MERCHANT_DETAIL)
    public Result<MerchantDetailRespDTO> merchantDetail(@RequestBody @Validated PrimaryIdDTO dto) {
        return Result.success(merchantService.merchantDetail(dto));
    }

    @ApiOperation(value = "商户分页列表")
    @PostMapping(value = MerchantUrl.MERCHANT_LIST_PAGE)
    public Result<PageResult<MerchantListPageRespDTO>> merchantListPage(@RequestBody @Validated MerchantListPageReqDTO dto) {
        return Result.page(PageResult.getPageResult(merchantService.merchantListPage(dto)));
    }

    @SystemLog
    @ApiOperation(value = "商户新增")
    @PostMapping(value = MerchantUrl.MERCHANT_ADD)
    public Result<Void> merchantAdd(@RequestBody @Validated MerchantAddReqDTO dto) {
        merchantService.merchantAdd(dto);
        return Result.success();
    }

    @SystemLog
    @ApiOperation(value = "商户修改")
    @PostMapping(value = MerchantUrl.MERCHANT_UPDATE)
    public Result<Void> merchantUpdate(@RequestBody @Validated MerchantUpdateReqDTO dto) {
        merchantService.merchantUpdate(dto);
        return Result.success();
    }

    @ApiOperation(value = "所有商户选择")
    @PostMapping(value = MerchantUrl.MERCHANT_SELECT)
    public Result<List<MerchantSelectRespDTO>> merchantSelect() {
        return Result.success(merchantService.merchantSelect());
    }
}
